package javase.list;

import com.alibaba.druid.support.json.JSONUtils;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

@Slf4j
public class ListDemo {


    //LinkedList访问
    private static void linkedListGet(int elementCount, int loopCount) {
        List<Integer> list = IntStream.rangeClosed(1, elementCount).boxed().collect(Collectors.toCollection(LinkedList::new));
        IntStream.rangeClosed(1, loopCount).forEach(i -> list.get(ThreadLocalRandom.current().nextInt(elementCount)));
    }

    //ArrayList访问
    private static void arrayListGet(int elementCount, int loopCount) {
        List<Integer> list = IntStream.rangeClosed(1, elementCount).boxed().collect(Collectors.toCollection(ArrayList::new));
        IntStream.rangeClosed(1, loopCount).forEach(i -> list.get(ThreadLocalRandom.current().nextInt(elementCount)));
    }

    //LinkedList插入
    private static void linkedListAdd(int elementCount, int loopCount) {
        List<Integer> list = IntStream.rangeClosed(1, elementCount).boxed().collect(Collectors.toCollection(LinkedList::new));
        IntStream.rangeClosed(1, loopCount).forEach(i -> list.add(ThreadLocalRandom.current().nextInt(elementCount),1));
    }

    //ArrayList插入
    private static void arrayListAdd(int elementCount, int loopCount) {
        List<Integer> list = IntStream.rangeClosed(1, elementCount).boxed().collect(Collectors.toCollection(ArrayList::new));
        IntStream.rangeClosed(1, loopCount).forEach(i -> list.add(ThreadLocalRandom.current().nextInt(elementCount),1));
    }

    public static void main(String[] args) {

//        是是
//        int[] arr = {1, 2, 3};
//        List list = Arrays.asList(arr);
//        log.info("list:{} size:{} class:{}", list, list.size(), list.get(0).getClass());
//
//
//        String[] arr2 = {"1", "2", "3"};
//        List list2 = new ArrayList(Arrays.asList(arr));
//        arr2[1] = "4";
//        try {
//            list.add("5");
//        } catch (Exception ex) {
//            ex.printStackTrace();
//        }
//        log.info("arr:{} list:{}", Arrays.toString(arr), list);
//        Map map = IntStream.rangeClosed(1, 10).boxed().collect(Collectors.toMap(Function.identity(), Order::new));
//        log.info("map:{} ", map);
        String s = "{\"consulting_report\":\"KJ2017008_warning000007_report\",\"verification_opinion\":\"KJ2017008_warning000007_option\"}";
        System.out.println(JSON.parse(s));

        int i = 0;
        for (char j = 0; j < s.length(); j++) {
            i++;
        }
        System.out.println(i);
    }
}
